﻿using System.Collections.Generic;
using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.ZilLionOss.Domain.Entitys;
using ZilLion.Service.ZilLionOss.Domain.Repositorys.Interface;
using ZilLion.Service.ZilLionOss.Domain.Services.Interface;

namespace ZilLion.Service.ZilLionOss.Domain.Services
{
    public class OssRoleService : IOssRoleService
    {
        private readonly IOssRoleRepository _ossRoleRepository;
        private readonly IOssRoleRouteRepository _ossRoleRouteRepository;

        public OssRoleService(IOssRoleRepository ossRoleRepository, IOssRoleRouteRepository ossRoleRouteRepository)
        {
            _ossRoleRepository = ossRoleRepository;
            _ossRoleRouteRepository = ossRoleRouteRepository;
        }

        public IEnumerable<OssRoleEntity> GetAllRoles()
        {
            return _ossRoleRepository.GetAllRoles();
        }

        public OssRoleEntity GetRole(long roleid)
        {
            return _ossRoleRepository.GetOssRoleById(roleid);
        }

        public void DeleteRole(long roleid)
        {
            using (var unit = new UnitOfWork())
            {
                _ossRoleRepository.DeleteRole(roleid, unit);
                _ossRoleRouteRepository.DeleteRouteByRoleid(roleid, unit);
                unit.Complete();
            }
        }
    }
}